//
//  TPAppointmentCell.m
//  Yimei
//
//  Created by xiaowu xiaowu on 2017/10/27.
//  Copyright © 2017年 xiaowu xiaowu. All rights reserved.
//

#import "TPAppointmentCell.h"
#import "TPHomeModel.h"
@implementation TPAppointmentCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
       
        [self setup];
    }
    return self;
}
-(void)setup{
    
    [self.title_label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0.0).offset(10.0);
        make.top.mas_equalTo(5.0);
        make.height.mas_equalTo(27.0);
        make.right.mas_equalTo(-10.0);
    }];
    
    self.image_view.contentMode = UIViewContentModeScaleAspectFill;
    [self.image_view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10.0f);
        make.top.mas_equalTo(self.title_label.mas_bottom).offset(5.0);
        make.bottom.mas_equalTo(-10.0f);
        make.width.mas_equalTo(100);
        make.height.mas_lessThanOrEqualTo(110.0);
        make.height.mas_greaterThanOrEqualTo(80.0);
    }];
    
    self.detail_label.numberOfLines = 2;
    self.detail_label.font = fontSystemOfSize(16);
  
    
    [self.date_label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.image_view.mas_right).offset(10.0);
        make.bottom.mas_equalTo(self.image_view.mas_bottom);
        make.height.mas_equalTo(self.title_label.mas_height);
    }];
    
    self.price_label.font = [UIFont boldSystemFontOfSize:18];
    self.price_label.textColor = TPAllBackgroundColor;
    [self.price_label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.date_label.mas_left);
        make.bottom.mas_equalTo(self.date_label.mas_top);
        make.height.mas_equalTo(self.title_label.mas_height);
    }];
    
    self.detail_label.font = fontSystemOfSize(17);
    self.detail_label.textColor = TPBlack_333333;
    [self.detail_label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.date_label.mas_left);
        make.top.mas_equalTo(self.image_view.mas_top);
        make.right.mas_equalTo(self.title_label.mas_right);
        make.bottom.mas_equalTo(self.price_label.mas_top);
    }];
    [self.titleButton setTitle:@"已完成" forState:UIControlStateNormal];
    [self.titleButton setTitleColor:TPAllBackgroundColor forState:UIControlStateNormal];
    [self.titleButton setBackgroundImageColor:[UIColor clearColor] forState:UIControlStateNormal];
    [self.titleButton setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    [self.titleButton setTitle:@"退款" forState:UIControlStateSelected];
    [self.titleButton setBackgroundImageColor:TPAllBackgroundColor forState:UIControlStateSelected];
    [self.titleButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-10.0);
        make.bottom.mas_equalTo(self.date_label.mas_bottom);
        make.height.mas_equalTo(30.0);
        make.width.mas_equalTo(70.0);
    }];
    
    
}
-(void)setModel:(TPAppointModel *)model{
    _model = model;
    
    self.titleButton.hidden = YES;//self.type == TPAppointmentTypeAppoint;
    NSString *string = @"无疗程";
    self.title_label.text = [NSString stringWithFormat:@"%@：%@",self.type == TPAppointmentTypeAppoint ? @"订单号":@"预约号",xw_getNULLString(model.order_sn)];
    self.detail_label.text = model.product.goods_name;
    self.price_label.text = [NSString stringWithFormat:@"￥%@ %@",model.product.goods_price,string];
    NSMutableAttributedString *att = [[NSMutableAttributedString alloc]initWithString:self.price_label.text];
    [att addAttributes:@{NSFontAttributeName:fontSystemOfSize(12),NSForegroundColorAttributeName:TPBlack_999999} range:[self.price_label.text rangeOfString:string]];
     self.price_label.attributedText = att;
    self.date_label.text = [NSString stringWithFormat:@"预约时间：%@",model.time];
    [self.image_view ym_setImageWithURL:model.product.goods_image placeholderImage:defaultLogo];
}
@end


